package edu.dayu.controller;

import com.github.pagehelper.PageInfo;
import edu.dayu.pojo.Article;
import edu.dayu.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/admin")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping("/articleList")
    public PageInfo<Article> articleList(Article article){
        return articleService.articleList(article);
    }

    @PostMapping("/articleInsert")
    public void articleInsert(Article article){
        articleService.articleInsert(article);
    }

    @PostMapping("/articleUpdate")
    public void articleUpdate(Article article){
        articleService.articleUpdate(article);
    }

    @PostMapping("/articleDelete")
    public void articleDelete(Article article){
        articleService.articleDelete(article);
    }

    @PostMapping("/articleById")
    public Article articleById(Article article){
        List<Article> articleList = articleService.articleList(article).getList();
        Article article1 = new Article();
        for (Article article2 : articleList) {
            article1 = article2;
        }
        return article1;
    }
}
